package com.learning.security.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.learning.security.controller.vo.ApiSaveReqVO;
import com.learning.security.dal.dataobject.AdminApiDO;
import com.learning.security.dal.mysql.AdminApiMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 接口URI表 服务实现类
 * </p>
 *
 * @author xxx
 * @since 2024-10-04
 */
@Service
public class AdminApiServiceImpl extends ServiceImpl<AdminApiMapper, AdminApiDO> implements AdminApiService {

    @Autowired
    private AdminApiMapper adminApiMapper;

    @Override
    public boolean createApi(ApiSaveReqVO reqVO) {
        return Db.save(new AdminApiDO().setName(reqVO.getName())
                .setPath(reqVO.getPath())
                .setPermission(reqVO.getPermission())
                .setType(reqVO.getType())
                .setSort(reqVO.getSort())
                .setStatus(reqVO.getStatus()));
    }

    @Override
    public AdminApiDO getApiByPath(String requestURI) {

        return adminApiMapper.getApiByPath(requestURI);
    }
}
